<?php

namespace app\api\controller\app;

use app\admin\model\Article;
use app\admin\model\Articletype;
use app\admin\model\City;
use app\admin\model\Shop;
use app\admin\model\Shopjoin;
use app\api\service\MpService;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Http;
use fast\Random;
use think\Config;
use think\Validate;

/**
 */
class System extends Api
{
    protected $noNeedLogin = ['addShopJoin','articelLis'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

    }

    /**
     * 加盟信息
     */
    public function addShopJoin(){

        $city = $this->request->param('city');
        $name = $this->request->param('name');
        $mobile = $this->request->param('mobile');
        $org_id = $this->request->param('org_id');

        if($name == "" ){
            $this->error("请输入您的姓名");
        }
        if($mobile == "" ){
            $this->error("请输入您的手机号");
        }

        $pattern = "/^1[3456789]{1}\d{9}$/";
        $isPhone = preg_match($pattern,$mobile);
        if(!$isPhone){
            $this->error("请输入正确的手机号");

        }

        $shopJoinModel = new Shopjoin();
        $shopJoinModel->insert(['city'=>$city,'name'=>$name,'mobile'=>$mobile,'create_time'=>time(),'org_id'=>$org_id]);


        $ids = array();
        $ids[] ="oV1gG6RrSwxyTivsLZDs1jYBMBn4";
        $ids[]= "oV1gG6Z6dUTZbtGKRDghUMa9VfBw";

        $mpService = new MpService();
        foreach ($ids as $key=>$val){

            $param = array();
            $param['openid'] = $val;
            $param['name'] = $name.$mobile;
            $param['time'] = date("Y-m-d H:i");
            $mpService->joinNotify($this->wxApp,$param);
        }


        $this->success('多谢提交，我们会尽快联系您');
    }

    public function articelList(){

        $articeType = new Articletype();
        $articleModel = new Article();
        $list = $articeType->select();
        foreach ($list as $key=>$val){
           $list[$key]['contentList'] = $articleModel->where('type_id',$val['id'])->select();
        }
        $this->success('',$list);
    }

    public function articleInfo(){
        $articleModel = new Article();
        $name = $this->request->param('name');
        $article = $articleModel->where('name',$name)->find();
        $this->success('',$article);
    }


}
